package com.drug.mingkang.controller;

import com.drug.mingkang.model.HqImm;
import com.drug.mingkang.model.HqRicher;
import com.drug.mingkang.model.vo.FinancialDetailsVo;
import com.drug.mingkang.permission.model.PerUsers;
import com.drug.mingkang.service.HqRicherService;
import com.drug.mingkang.utils.Tools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 总公司财务明细(HqRicher)表控制层
 *
 * @author wenchangjian
 * @since 2020-08-11 12:00:13
 */
@RestController
@RequestMapping("hqRicher")
@Api(value = "总公司财务明细控制层", tags = "总公司财务明细Contorller")
public class HqRicherController {
    /**
     * 服务对象
     */
    @Resource
    private HqRicherService hqRicherService;
    @Resource
    private Tools tools;

    /**
     * 显示所有分公司
     * @return 分公司列表
     */
    @ApiOperation(value = "显示所有分公司", notes = "显示所有分公司", httpMethod = "POST", response = List.class)
    @PostMapping("showGs")
    public List<HqImm> showGs() {
        return hqRicherService.showGs();
    }

    /**
     * 显示所有财务明细
     * @param vo 参数列表
     * @return 财务明细列表
     */
    @ApiOperation(value = "显示所有财务明细", notes = "显示所有财务明细", httpMethod = "POST", response = Map.class)
    @PostMapping("showAll")
    public Map<String, Object> showAll(FinancialDetailsVo vo) {
        List<HqRicher> list;
        int count;
        //判断分公司id
        if (StringUtils.isEmpty(vo.getImmId())) {
            list = hqRicherService.queryAllByLimits(vo);
            count = hqRicherService.selectCounts(vo);
        } else {
            list = hqRicherService.queryAllByLimit(vo);
            count = hqRicherService.selectCount(vo);
        }
        return tools.limit(list, count);
    }

    /**
     * 查询当前登录 公司财务 今日收入 以及本月收入
     * @param session 用户session
     * @return 今日收入 以及本月收入
     */
    @ApiOperation(value = "查询当前登录 公司财务 今日收入 以及本月收入", notes = "查询当前登录 公司财务 今日收入 以及本月收入", httpMethod = "POST", response = List.class)
    @PostMapping("findTodayIncomeOrMonthIncome")
    public List<Double> findTodayIncomeOrMonthIncome(HttpSession session) {
        PerUsers perUsers = (PerUsers) session.getAttribute("perUsers");
        //判断是否总公司
        String z = "0";
        if (z.equals(perUsers.getCompanyId())) {
            return hqRicherService.findTodayIncomeOrMonthIncome(z);
        } else {
            return hqRicherService.findTodayIncomeOrMonthIncome(perUsers.getCompanyId());
        }
    }

    /**
     * 查询当前登录公司财务总金额
     * @param session 用户session
     * @return 财务总金额
     */
    @ApiOperation(value = "查询当前登录公司财务总金额", notes = "查询当前登录公司财务总金额", httpMethod = "POST", response = Double.class)
    @PostMapping("findSumMoney")
    public Double findSumMoney(HttpSession session) {
        PerUsers perUsers = (PerUsers) session.getAttribute("perUsers");
        //判断是否总公司
        String z = "0";
        if (z.equals(perUsers.getCompanyId())) {
            return hqRicherService.findSumMoney(z);
        } else {
            return hqRicherService.findSumMoney(perUsers.getCompanyId());
        }
    }

    /**
     *根据公司查询 财务明细
     * @param vo 参数列表
     * @param session 用户session
     * @return 财务明细列表
     */
    @ApiOperation(value = "根据公司查询 财务明细", notes = "根据公司查询 财务明细", httpMethod = "POST", response = Map.class)
    @PostMapping("findCompanyFinancialDetails")
    public Map<String, Object> findCompanyFinancialDetails(FinancialDetailsVo vo, HttpSession session) {
        List<FinancialDetailsVo> list = hqRicherService.findCompanyFinancialDetails(vo, session);
        int count = hqRicherService.findCompanyFinancialDetailsCount(vo, session);
        return tools.limit(list, count);
    }
}